//
//  YLHealthKitManager.h
//  HealthKitManager
//
//  Created by JuneLee on 2018/11/9.
//

#import <Foundation/Foundation.h>
#import <HealthKit/HealthKit.h>
#import "YLHealthKitModel.h"

typedef NS_ENUM(int, YLHealthKitType){
    YLHealthKitTypeHeight = (1UL << 1),
    YLHealthKitTypeWeight= (1UL << 2),
    YLHealthKitTypeFatWeight = (1UL << 3),
    YLHealthKitTypeBodyFat = (1UL << 4),
    YLHealthKitTypeBMI = (1UL << 5),
    YLHealthKitTypeBMR = (1UL << 6),
    YLHealthKitTypeStepCount = (1UL << 7),
    YLHealthKitTypeHeartRate = (1UL << 8),
    YLHealthKitTypeSleepAnalysis = (1UL << 9),
    YLHealthKitTypeDistance = (1UL << 10),
};

NS_ASSUME_NONNULL_BEGIN

@interface YLHealthKitManager : NSObject

+ (YLHealthKitManager *)sharedManager;

/** 授权 */
- (void)requestAuthorizationCompletion:(void (^ )(BOOL success, NSError *error))block;

/** 写入秤历史数据 */
- (void)writeHistoryData:(void (^)(YLHealthKitConfig *config))dataConfigBlock completion:(void (^ )(BOOL success, NSError *_Nullable error))block API_AVAILABLE(ios(8.0));

/** 写入秤数据 */
- (void)writeHealthKitDataBlock:(void (^)(YLHealthKitModel *healthModel))healthKitDataBlock completion:(void (^ )(BOOL success, NSError *_Nullable error))block;

/** 写入手环数据 */
- (void)writeBandHealthKitData:(void (^)(NSMutableArray<YLHealthKitModel *> *stepArray,NSMutableArray<YLHealthKitModel *> *sleepArray,NSMutableArray<YLHealthKitModel *> *heartArray))healthKitDataBlock completion:(void (^ )(BOOL success, NSError *_Nullable error))block;

/** 获取数据（步数、睡眠、心率、距离） */
- (void)gethealthKitDataWithHealthKitType:(YLHealthKitType)healthKitType startDate:(NSDate *)startDate endDate:(NSDate *)endDate completion:(void (^)(NSArray<YLHealthKitModel *> *_Nullable results, NSError *_Nullable error))block API_AVAILABLE(ios(8.0));
@end

NS_ASSUME_NONNULL_END



/**
 * 在info文件创建一个key为YLDHealthKitKey的NSDictionary字段
 * 在YLDHealthKitKey字段内，创建一个key为read的Array字段以及一个key为share的Array字段
 * 在read、share字段中填写需要请求的类型标识(标识的类型为string)
 * bmi、bmr、bodyFat、fatWeight、heartRate、height、stepCount、weight、sleepAnalysis
 *
 *    <key>YLDHealthKitKey</key>
 *  <dict>
 *      <key>share</key>
 *      <array>
 *          <string>bmi</string>
 *          <string>bmr</string>
 *          <string>bodyFat</string>
 *          <string>fatWeight</string>
 *          <string>heartRate</string>
 *          <string>stepCount</string>
 *          <string>height</string>
 *          <string>weight</string>
 *          <string>sleepAnalysis</string>
 *      </array>
 *      <key>read</key>
 *      <array>
 *          <string>bmi</string>
 *          <string>bmr</string>
 *          <string>bodyFat</string>
 *          <string>fatWeight</string>
 *          <string>heartRate</string>
 *          <string>stepCount</string>
 *          <string>height</string>
 *          <string>weight</string>
 *          <string>sleepAnalysis</string>
 *          </array>
 *    </dict>
 *
 */
